Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Entities.Users

Namespace Checks
    Public Class MembershipUserSuperUserRatio
        Inherits MultilingualBase
        Implements IDnnSecurityCheck


        Public ReadOnly Property DisplayName As String Implements IDnnSecurityCheck.DisplayName
            Get
                Return GetTranslationFor (Me.GetType.Name & ".DisplayName")
            End Get
        End Property

        Private _ShortInfoText As String

        Public ReadOnly Property ShortInfoText() As String Implements IDnnSecurityCheck.ShortInfoText
            Get
                Return GetTranslationFor (Me.GetType.Name & ".ShortInfoText")
            End Get
        End Property

        Public ReadOnly Property Description() As String Implements IDnnSecurityCheck.Description
            Get
                Return GetTranslationFor (Me.GetType.Name & ".Description")
            End Get
        End Property

        Public ReadOnly Property SecurityRiskClassification As SecurityRiskClassification _
            Implements IDnnSecurityCheck.SecurityRiskClassification
            Get
                Dim res As IDnnSecurityResult =
                        Results.OrderByDescending (Function(x) x.SecurityRiskClassification).FirstOrDefault
                If res IsNot Nothing Then
                    Return res.SecurityRiskClassification
                End If

                Return SecurityRiskClassification.Ok
            End Get
        End Property

        Private _results As New List(Of IDnnSecurityResult)

        Public ReadOnly Property Results() As List(Of IDnnSecurityResult) Implements IDnnSecurityCheck.Results
            Get
                Return _results
            End Get
        End Property

        Public Sub Execute (ByVal portalSettings As PortalSettings, ByVal result As IAsyncResult) _
            Implements IDnnSecurityCheck.Execute
            Dim users As IEnumerable(Of UserInfo) =
                    UserController.GetUsers (portalSettings.PortalId).Cast (Of UserInfo)()
            Dim filteredUsers = users.Where (Function(x) x.Membership.Approved = True)

            Dim admins As IEnumerable(Of UserInfo) = UserController.GetUsers (- 1).Cast (Of UserInfo)()
            Dim filteredAdmins = admins.Where (Function(x) x.Membership.Approved = True)

            _ShortInfoText = CStr (filteredUsers.Count()) + "/" + CStr (filteredUsers.Count())
        End Sub

        Public Overloads Sub LoadRessourceFile (ByVal fileName As String) Implements IDnnSecurityCheck.LoadRessourceFile
            MyBase.LoadRessourceFile (fileName)
        End Sub
    End Class
End Namespace

